package 组合数学;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class 数位排序 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int m = scanner.nextInt();
        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; i++) {
            arr[i] = i + 1;
        }
        Arrays.sort(arr, ((o1, o2) -> {
            if (getSum(o1) == getSum(o2)) return o1 - o2;
            return getSum(o1) - getSum(o2);
        }));
        System.out.println(arr[m - 1]);
    }

    //数位之和
    public static Integer getSum(Integer num) {
        if (num == null) {
            return 0; // 或者返回适当的默认值
        }
        int ans = 0;
        while (num != 0) {
            ans += num % 10;
            num /= 10;
        }
        return ans;
    }
}
